package com.wolf.controller;

import com.wolf.pojo.Wl_commodity_placeorigin;
import com.wolf.service.Wl_commodity_placeoriginService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Controller
public class Wl_commodity_placeoriginController {

    @Autowired
    Wl_commodity_placeoriginService wl_commodity_placeoriginService;

    /***
     * 查询所有产地信息
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_getAll")
    public String getAll(ModelMap modelMap){

        List<Wl_commodity_placeorigin> wl_commodity_placeoriginList=this.wl_commodity_placeoriginService.getAll();

        modelMap.addAttribute("wl_commodity_placeoriginList",wl_commodity_placeoriginList);

        return "table_wl_commodity_placeorigin";
    }

    /***
     * 多条件支持模糊查询产地信息
     * @param modelMap
     * @param chnorigin
     * @param engorigin
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_fuzzyQuery")
    public String fuzzyQuery(ModelMap modelMap, @RequestParam("chnorigin")String chnorigin, @RequestParam("engorigin")String engorigin, @RequestParam("beginTime")String beginTime, @RequestParam("endTime")String endTime, @RequestParam("status")String status){

        List<Wl_commodity_placeorigin> wl_commodity_placeoriginList=this.wl_commodity_placeoriginService.fuzzyQuery("%"+chnorigin+"%", "%"+engorigin+"%", beginTime, endTime, status);

        modelMap.addAttribute("wl_commodity_placeoriginList",wl_commodity_placeoriginList);

        return "table_wl_commodity_placeorigin";
    }

    /***
     * 新增产地信息
     * @param wl_commodity_placeorigin
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_insertSelective")
    public String insertSelective(Wl_commodity_placeorigin wl_commodity_placeorigin){

        if(wl_commodity_placeorigin.getStatus()==null){
            wl_commodity_placeorigin.setStatus(1);
        }

        int result=this.wl_commodity_placeoriginService.insertSelective(wl_commodity_placeorigin);

        System.out.println(result);

        return "redirect:wl_commodity_placeorigin_getAll";
    }

    /***
     * 根据主键查询产地实体
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_getById")
    public String getById(String id,ModelMap modelMap){

        Wl_commodity_placeorigin wl_commodity_placeorigin=this.wl_commodity_placeoriginService.selectByPrimaryKey(id);

        System.out.println(wl_commodity_placeorigin.getStatus());

        modelMap.addAttribute("wl_commodity_placeorigin",wl_commodity_placeorigin);

        return "wl_commodity_placeorigin_update";
    }

    /***
     * 修改产地信息
     * @param wl_commodity_placeorigin
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_update")
    public String update(Wl_commodity_placeorigin wl_commodity_placeorigin){
        int result=this.wl_commodity_placeoriginService.updateByPrimaryKey(wl_commodity_placeorigin);

        System.out.println(result);

        return "redirect:wl_commodity_placeorigin_getAll";
    }

    /***
     * 删除产地信息（禁用）
     * @param id
     * @return
     */
    @RequestMapping("wl_commodity_placeorigin_delete")
    public String delete(String id){
        Wl_commodity_placeorigin wl_commodity_placeorigin=this.wl_commodity_placeoriginService.selectByPrimaryKey(id);

        wl_commodity_placeorigin.setStatus(0);

        int result=this.wl_commodity_placeoriginService.updateByPrimaryKey(wl_commodity_placeorigin);

        System.out.println(result);

        return "redirect:wl_commodity_placeorigin_getAll";
    }
}
